package com.example.smarthourse;

import com.example.uart.Uart;

import DataProcessing.LedControl;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class LedsActivity extends Activity{
	private ImageButton	 led1_off_Button;
	private ImageButton  led1_on_Button;
	private ImageButton	 led2_off_Button;
	private ImageButton  led2_on_Button;
	private ImageButton	 led3_off_Button;
	private ImageButton	 led3_on_Button;
	private Boolean  flag1=true;
	private Boolean	 flag2=true;
	private Boolean	 flag3=true;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_leds);
		led1_off_Button = (ImageButton)findViewById(R.id.Led1_off);
		led2_off_Button = (ImageButton)findViewById(R.id.Led2_off);
		led3_off_Button = (ImageButton)findViewById(R.id.Led3_off);
		led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1of));
		led2_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led2of));
		led3_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led3of));
		led1_off_Button.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(flag1)	
				{
					flag1=!new LedControl().Led1_On();
					//led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1_on));
				}		
				else{
					flag1=!new LedControl().Led1_Off();
					//	led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1of));
				}
			}
		});
		led2_off_Button.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(flag2)	
				{
					flag2=!new LedControl().Led2_On();
					//led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1_on));
				}		
				else{
					flag2=!new LedControl().Led2_Off();
					//	led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1of));
				}
			}
		});
		led3_off_Button.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(flag3)	
				{
					flag3=!new LedControl().Led3_On();
					//led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1_on));
				}		
				else{
					flag3=!new LedControl().Led3_Off();
					//	led1_off_Button.setImageDrawable(getResources().getDrawable(R.drawable.led1of));
				}
			}
		});
	}

}
